import {abstract_point} from "./abstract-point";
import {http} from "./http";

/**
 * 刷考试积分(+20)
 */
export class epoint extends abstract_point{

    /**
     *
     * @param user {user} 对象
     * @param time {Number} 执行次数
     * @param score {Number} 打算考的分数
     * @param value {Number} 每次应该刷多少分
     */
    constructor(user,time=3,score=2,value=20){
        super(user,time);
        this.score=score;
        this.value=value;
        this.nickName="刷考试的";
    }


    async request(){

        let paperId=2637;
        let series=24;


        await http.get(`/ess/service/getpaper?paperId=${paperId}&series=${series}`);

        let answer=await (await http.get(`/ess/service/getpaper?paperId=${paperId}&series=${series}_answer`)).text();
        answer=JSON.parse(answer.split("\n")[2]);
        answer.forEach(a=>Reflect.deleteProperty(a,"score"));
        let i=0;
        for(let a of answer){
            i++;
            if(i>30){
                a.answerNo="";
            }
        }


        await http.post("/sss/service/coursewareService!commitExercises.do"
        ,{
            domainCode:this.user.domainCode
            ,userAccount:this.user.userAccount
            ,paperId:paperId
            ,series:series
            ,myExamAnswer:JSON.stringify(answer)
            ,ssid:this.user.sid
            ,type:1
            ,validate:""
            ,timestamp:new Date()}
            );



        await http.post("/pss/service/postPoint?operateType=epoint" +
            "&userAccount=" + this.user.userAccount +
            "&domainCode=" + this.user.domainCode +
            "&"+"timestamp=" + new Date() +
            "&exerScore=" + this.score +
            "&expointValue=" +this.value +
            "&ssid=" +this.user.sid
        );
    }

}

